import java.util.ArrayList;
import java.util.List;

public class partition {
    List<List<String>> res = new ArrayList<>();
    List<String> cur = new ArrayList<>();
    public List<List<String>> partition(String s) {

        a(s,0,new StringBuilder());
        return res;
    }
    public void a(String s,int start,StringBuilder sb){
        if(start == s.length()){
            res.add(new ArrayList<>(cur));
            return;
        }
        for(int i = start; i < s.length();i++){
            sb.append(s.charAt(i));
            if(check(sb)){
                cur.add(sb.toString());
                a(s,i+1,new StringBuilder());
                cur.remove(cur.size()-1);
            }
        }
    }
    public boolean check(StringBuilder sb){
        for(int i =0; i< sb.length()/2;i++){
            if(sb.charAt(i) != sb.charAt(sb.length()- 1-i)){
                return false;
            }
        }
        return true;
    }
}
